package me.ezjs.system.model.user;

import com.google.common.collect.ImmutableList;
import me.ezjs.framework.bridge.BaseObject;
import org.springframework.util.StringUtils;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.List;

/**
 * 系统管理员角色
 * <p/>
 * Created by zero-mac on 16/3/10.
 */
@Entity
@Table(name = "Z_SYSTEM_ROLE")
public class SystemRole extends BaseObject {

    private String name;// 角色名称
    private String permissions;//角色细分权限

    private String code;//角色编号
    private String description;//描述

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPermissions() {
        return permissions;
    }

    public void setPermissions(String permissions) {
        this.permissions = permissions;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    @Transient
    public List<String> getPermissionList() {
        if (permissions == null) {
            return new ArrayList<>();
        }
        return ImmutableList.copyOf(StringUtils.split(permissions, ","));
    }

}
